using System;
using System.Diagnostics;

namespace OpenRay
{
	//Immutable class
	public struct Point
	{
		public readonly float X, Y, Z;
		private const double Delta = 0.00005;
		
		public Point(float x, float y, float z, float w)
		{
			Debug.Assert( w != 0f, "Point(x, y, z, w): A value of 0 was given for w" );
			
			float temp = 1f / w;
			X = x * temp;
			Y = y * temp;
			Z = z * temp;
		}
		
		public Point(float x, float y, float z)
		{
			X = x;
			Y = y;
			Z = z;
		}
		
		public static Point operator + (Point p, Vector v)
		{
			return new Point( p.X + v.X, p.Y + v.Y, p.Z + v.Z ); 	
		}
		
		
		public bool Equals (Point v)
		{			
			return  Math.Abs( X - v.X ) < Delta &&
				   	Math.Abs( Y - v.Y ) < Delta &&
					Math.Abs( Z - v.Z ) < Delta;
		}
		
		public override int GetHashCode()
		{
			return (int)X + (int)Y + (int)Z + (int)1.0;
		}
		
		public override string ToString()
		{			
			return X.ToString() + ", " + Y.ToString() + ", " + Z.ToString();
		}
		
		public static Point operator - (Point p, Vector v)
		{
			return new Point( p.X - v.X, p.Y - v.Y, p.Z - v.Z ); 	
		}
		
		public static Vector operator - (Point p1, Point p2)
		{
			return new Vector( p1.X - p2.X,
			                   p1.Y - p2.Y,
			                   p1.Z - p2.Z );	
		}
	}
}

